package com.fyzk.activity.dialog;

import android.os.Build;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fyzk.base.BaseActivity;
import com.tyjc.lottery.R;

/**
 * 对话框形式的Activity
 * @author fxs
 *
 */
public abstract class DialogActivity extends BaseActivity{
	
	private ImageView title_iv;
	private TextView title_tv;
	private LinearLayout top_ll;
	
	protected LinearLayout center_ll;
	private LinearLayout bottom_ll;
	private LinearLayout bottom_ll1;
	private LinearLayout bottom_ll2;
	
	private TextView bottom_sure_tv;
	private TextView bottom_sure_tv2;
	private TextView bottom_cancel_tv;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.dialog_activity);
		//设置不可点击边框以外区域
		if(Build.VERSION.SDK_INT >= 11 ){
			setFinishOnTouchOutside(false);
		}else{
			
		}
		
		initView();
	}
	
	/**
	 * 控件初始化
	 */
	private void initView(){
		top_ll = (LinearLayout) findViewById(R.id.dialog_activity_top_ll);
		top_ll.setGravity(setTopGravity());
		title_iv = (ImageView) findViewById(R.id.dialog_activity_top_iv);
		if (setTitleImg() == 0) {
			title_iv.setVisibility(View.INVISIBLE);
		}else{
			title_iv.setImageResource(setTitleImg());
		}
		title_tv = (TextView) findViewById(R.id.dialog_activity_top_tv);
		title_tv.setText(setTitle());
		
		center_ll = (LinearLayout) findViewById(R.id.dialog_activity_center_ll);
		bottom_ll = (LinearLayout) findViewById(R.id.dialog_activity_bottom);
		bottom_ll1 = (LinearLayout) findViewById(R.id.dialog_activity_bottom1);
		bottom_ll2 = (LinearLayout) findViewById(R.id.dialog_activity_bottom2);
		View view = addCenterView();
		if (view != null) {
			center_ll.addView(view);
		}
		
		bottom_cancel_tv = (TextView) findViewById(R.id.dialog_activity_cancel);
		bottom_cancel_tv.setOnClickListener(this);
		bottom_sure_tv = (TextView) findViewById(R.id.dialog_activity_sure);
		bottom_sure_tv.setOnClickListener(this);
		bottom_sure_tv2 = (TextView) findViewById(R.id.dialog_activity_sure2);
		bottom_sure_tv2.setOnClickListener(this);
		
	}
	
	public int setTopGravity(){
		return Gravity.CENTER_VERTICAL;
	}
	/**
	 * 设置图标
	 * @return
	 */
	protected abstract int setTitleImg();
	/**
	 * 设置标题
	 * @return
	 */
	protected abstract String setTitle();
	/**
	 * 添加中间view控件
	 * @return
	 */
	protected abstract View addCenterView();
	/**
	 * 点击确定按钮
	 */
	protected abstract void onClickSure();
	/**
	 * 点击取消按钮
	 */
	protected abstract void onClickCancel();
	
	public void setBottomVisibility(int visibility){
		bottom_ll.setVisibility(visibility);
	}
	
	/**
	 * 只显示"确定"按钮
	 */
	public void setShowBottom2(){
		bottom_ll1.setVisibility(View.GONE);
		bottom_ll2.setVisibility(View.VISIBLE);
	}
	

	@Override
	public void onClick(View arg0) {
		switch (arg0.getId()) {
		case R.id.dialog_activity_cancel:
			onClickCancel();
			break;
		case R.id.dialog_activity_sure:
			onClickSure();
			break;
		case R.id.dialog_activity_sure2:
			onClickSure();
			break;
		default:
			break;
		}
		
		
	}
}
